<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
    $(function() {
        $('#processStartRightForm').form({
            url : '${path}/processType/saveStartRight',
            onSubmit : function() {
                progressLoad();
                var isValid = $(this).form('validate');
                if (!isValid) {
                    progressClose();
                }
                return isValid;
            },
            success : function(result) {
                progressClose();
                result = $.parseJSON(result);
                if (result.success) {
                    showMsg(result.msg);
                    parent.processTypetreegrid.treegrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_dataGrid这个对象，是因为user.jsp页面预定义好了
                } else {
                    var form = $('#processStartRightForm');
                    parent.$.messager.alert('错误', result.msg, 'error');
                }
            }
        });
    });
    function chooseUserofStartRight(multiSelect) {
    	var userids= $('#processStartRightForm [name=userids]').val();
    	console.log(userids)
        var url="${ctxPath}/user/toSelectUser?userids="+userids;
        var title='选人';
        var width=250;
        if(multiSelect){
            url="${ctxPath}/user/toMultiSelectUser?userids="+userids;
            title='选人';
            width=500;
        }
        var dialog= $('<div>').dialog({
            title:title,
            href:url,
            width : width,
            height : 500,
            onClose : function() {
                $(this).dialog('destroy');
            },
            buttons:[{
                text:'确定',
                handler:function () {
                    if (!multiSelect) {
                        var treeObj = $.fn.zTree.getZTreeObj("singleUserTree"); //获取全部节点数据
                        var nodes = treeObj.getCheckedNodes(true);
                        var id = nodes[0].id;
                        var name = nodes[0].text;
                        id = id.replace('USER', '');//用户id
                        $('#processStartRightForm [name=userids]').val(id);
                        $('#processStartRightForm [name=userNames]').text(name);
                    } else {
                        var treeObj = $.fn.zTree.getZTreeObj("multiUserTree"); //获取全部节点数据
                        var nodes = treeObj.getCheckedNodes(true);
                        var ids = [], names = [];
                        if (nodes.length > 0) {
                            for (var i = 0; i < nodes.length; i++) {
                                var id = nodes[i].id;
                                if (id.indexOf('USER') > -1) {
                                    id = id.replace('USER', '');//用户id
                                    ids.push(id);
                                    names.push(nodes[i].text);
                                }

                            }
                            
                            $('#processStartRightForm [name=userids]').val(ids);
                            $('#processStartRightForm [name=userNames]').val(names);
                        }
                    }
                	dialog.dialog('close');
                }
            },{
                text:'取消',
                handler:function () {
                	dialog.dialog('close');
                }
            }]
        });
    }
    function chooseRolesofStartRight(multiSelect){
    	var roleids=$('#processStartRightForm [name=roleids]').val();
    	var dialog=$('<div>').dialog({
    		 title:'选择角色',
    		 href:'${ctxPath}/role/roleSelect?roleids='+roleids+'&flag='+multiSelect,
    		 width : '80%',
             height : '80%',
             onClose : function() {
                 $(this).dialog('destroy');
             },
             buttons:[{
                 text:'确定',
                 handler:function () {
                	 var roleids=[];
                	 var roleNames=[];
                	 var rows=roleSelectDataGrid.datagrid('getSelections');
                	 if(rows.length>0){
                		 for(var i=0;i<rows.length;i++){
                			 roleids.push(rows[i].id);
                			 roleNames.push(rows[i].name);
                		 }
                	 }
                	 $('#processStartRightForm [name=roleids]').val(roleids.join(','))
                	 $('#processStartRightForm [name=roleNames]').val(roleNames.join(','))
                	 dialog.dialog('close');
                 }
             }]
    	})
    }
    function chooseDeptsofStartRight(multiSelect){
    	var deptids=$('#processStartRightForm [name=deptids]').val();
    	var dialog=$('<div>').dialog({
    		 title:'选择部门',
    		 href:'${ctxPath}/organization/organizationSelect?deptids='+deptids+'&flag='+multiSelect,
    		 width : '80%',
             height : '80%',
             onClose : function() {
                 $(this).dialog('destroy');
             },
             buttons:[{
                 text:'确定',
                 handler:function () {
                	 var deptids=getMultiOrgIds();
                	 var deptNames=getMultiOrgNames();
                	 $('#processStartRightForm [name=deptids]').val(deptids)
                	 $('#processStartRightForm [name=deptNames]').val(deptNames)
                	 dialog.dialog('close');
                 }
             }]
    	})
    }
    function clearStartRightUsers(){
    	  $('#processStartRightForm [name=userids]').val('');
          $('#processStartRightForm [name=userNames]').val('');
    }
    function clearStartRightRoles(){
    	  $('#processStartRightForm [name=roleids]').val('');
          $('#processStartRightForm [name=roleNames]').val('');
    }
    function clearStartRightDepts(){
    	 $('#processStartRightForm [name=deptids]').val('')
    	 $('#processStartRightForm [name=deptNames]').val('')
    }
</script>
<div class="easyui-layout" data-options="fit:true,border:false" >
    <div data-options="region:'center',border:false" style="overflow-x:hidden;overflow-y: auto;padding: 3px;" >
        <form id="processStartRightForm" method="post">
            <table class="grid">
            <tr>
            	<td>是否公开，不做发起权限控制</td>
            	<td><input type="checkbox" name="status" value="1" <c:if test="${actStartRight.status==1}">checked</c:if>/>是</td>
            </tr>
 				<tr>
                      <td>发起用户</td>
                      <td>
                      <input type="hidden" name="id" value="${actStartRight.id}"/>
                      <input type="hidden" name="procdefid" value="${procdefid}"/>
                      <input type="hidden" name="userids" value="${actStartRight.userids}"/>
                      	<textarea class="easyui-text-2" style="min-height:50px;width:80%" name="userNames">${actStartRight.userNames}</textarea>
                      	<a href="javascript:;" onclick="chooseUserofStartRight(true)">选人</a>
                      	<a href="javascript:;" onclick="clearStartRightUsers()">清空</a>
                      </td>
                 </tr>
                 <tr>
                      <td style="width:100px;">发起角色</td>
                      <td>
                      <input type="hidden" name="roleids" value="${actStartRight.roleids}"/>
                      	<textarea class="easyui-text-2" style="min-height:50px;width:80%" name="roleNames">${actStartRight.roleNames}</textarea>
                      	<a href="javascript:;" onclick="chooseRolesofStartRight(false)">选择</a>
                      	<a href="javascript:;" onclick="clearStartRightRoles()">清空</a>
                      </td>
                 </tr>
                 <tr>
                      <td>发起部门</td>
                      <td>
                      <input type="hidden" name="deptids" value="${actStartRight.deptids}"/>
                      	<textarea class="easyui-text-2" style="min-height:50px;width:80%" name="deptNames">${actStartRight.deptNames}</textarea>
                      	<a href="javascript:;" onclick="chooseDeptsofStartRight(true)">选择</a>
                      	<a href="javascript:;" onclick="clearStartRightDepts()">清空</a>
                      </td>
                 </tr>
            </table>
        </form>
    </div>
</div>